

#ifndef __COMM_MSG_MOVE_CTRL_H__
#define __COMM_MSG_MOVE_CTRL_H__

#include "comm/comm_topic_name.h"
#include "comm/comm_base.h"
#include <comm_msg/move_ctrl.h>
#include <ros/ros.h>
#include <iostream>
#include <list>
#include <vector>

using namespace std;

/**************************************************************************************
功能描述: 发布消息
修改记录:
**************************************************************************************/
class MOVE_CTRL_SENDER_C
{
public:
    MOVE_CTRL_SENDER_C(ros::NodeHandle &nh)
    {
        publisher_ = nh.advertise<comm_msg::move_ctrl>(TOPIC_NAME_MOVE_CTRL, 1);
    }

    void Send(BOOL isExistTask, BOOL isTeleCtrl, BOOL isCleaning, const MOVE_CTRL_INFO_STRU &stMoveCtrl, const MOVE_CTRL_SMOOTH_INFO_STRU &stCtrlSmooth)
    {
        comm_msg::move_ctrl stMsg;

        stMsg.isExistTask   = isExistTask;
        stMsg.isTeleCtrl    = isTeleCtrl;
        stMsg.isCleaning    = isCleaning;
        stMsg.steeringAngle = stMoveCtrl.turnAngle;
        stMsg.moveLinearVel = stMoveCtrl.linearVel;
        stMsg.isMoveSmooth  = stCtrlSmooth.isSmooth;
        stMsg.isStopSmooth  = stCtrlSmooth.isSmoothStop;
        
        publisher_.publish(stMsg);
    }

private:
    ros::Publisher publisher_;
};

/**************************************************************************************
功能描述: 接收消息
修改记录:
**************************************************************************************/
class MOVE_CTRL_RECEIVER_C
{
public:
    MOVE_CTRL_RECEIVER_C(ros::NodeHandle &nh)
    {
        subscriber_ = nh.subscribe(TOPIC_NAME_MOVE_CTRL, 1, &MOVE_CTRL_RECEIVER_C::ReceiveMsgCallBack, this);

        objInvalidTimer_.SetOverTime(0.15);
        isExistTask_               = false;
        isTeleCtrl_                = false;
        isCleaning_                = false;
        stMoveCtrl_.turnAngle      = 0.0;
        stMoveCtrl_.linearVel      = 0.0;
        stCtrlSmooth_.isSmooth     = false;
        stCtrlSmooth_.isSmoothStop = false;
    }

    INT32 Get(BOOL &isExistTask, BOOL &isTeleCtrl, BOOL &isCleaning, MOVE_CTRL_INFO_STRU &stMoveCtrl, MOVE_CTRL_SMOOTH_INFO_STRU &stCtrlSmooth) const
    {
        if (objInvalidTimer_.IsTimeOut()) {
            return -1;
        }

        isExistTask     = isExistTask_;
        isTeleCtrl      = isTeleCtrl_;
        isCleaning      = isCleaning_;
        stMoveCtrl      = stMoveCtrl_;
        stCtrlSmooth    = stCtrlSmooth_;

        return 0;
    }
    
private:
    ros::Subscriber             subscriber_;

    TIMER_C                     objInvalidTimer_;
    BOOL                        isExistTask_;
    BOOL                        isTeleCtrl_;
    BOOL                        isCleaning_;
    MOVE_CTRL_INFO_STRU         stMoveCtrl_;
    MOVE_CTRL_SMOOTH_INFO_STRU  stCtrlSmooth_;

    void ReceiveMsgCallBack(const comm_msg::move_ctrl::ConstPtr &pstMsg)
    {
        R_ASSERT(pstMsg != NULL, NOTHING);

        objInvalidTimer_.Reset();

        isExistTask_               = pstMsg->isExistTask;
        isTeleCtrl_                = pstMsg->isTeleCtrl;
        isCleaning_                = pstMsg->isCleaning;
        stMoveCtrl_.turnAngle      = pstMsg->steeringAngle;
        stMoveCtrl_.linearVel      = pstMsg->moveLinearVel;
        stCtrlSmooth_.isSmooth     = pstMsg->isMoveSmooth;
        stCtrlSmooth_.isSmoothStop = pstMsg->isStopSmooth;
    }
};


#endif

